<!DOCTYPE html>
<html>
<head>
    <title>模具换件记录_关联备件</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <Card>
        <p slot="title">{{title}}</p>
        <i-form :model="moldSpUsedRecord" :label-width="80">
            <Row>
                <i-col span="11">
                    <Form-item label="型芯条码" prop="uniqueCode">
                        <i-input v-model="moldSpUsedRecord.uniqueCode" placeholder="型芯备件唯一码" @keyup.enter.native="queryMoldSpStock" autofocus/>
                    </Form-item>
                </i-col>
            </Row>
            <Row>
                <i-col span="11">
                    <Form-item label="型芯名称" prop="sparePartsName">
                        <i-input v-model="moldSpUsedRecord.sparePartsName" placeholder="库存状态" readonly/>
                    </Form-item>
                </i-col>
                <i-col span="11">
                    <Form-item label="型芯规格" prop="sparePartsSpec">
                        <i-input v-model="moldSpUsedRecord.sparePartsSpec" placeholder="型芯备件唯一码" readonly/>
                    </Form-item>
                </i-col>
            </Row>
        </i-form>
    </Card>
</div>

<script>
    let vm = new Vue({
        el: '#rrapp',
        data: {
            title: '请扫码需要使用的型芯：',
            moldSpUsedRecord:{
                uniqueCode: '', // 型芯条码
                sparePartsName:'', // 型芯名称
                sparePartsSpec:'', // 型芯规格
                sparePartsId: '' // 型芯库存ID
            }
        },
        methods: {
            // 查询模具型芯库存
            queryMoldSpStock: function (){
                let _this = this;
                if(!this.moldSpUsedRecord.uniqueCode){
                    iview.Message.error('请扫码！');
                    return;
                }
                Ajax.request({
                    url: "../modulespstock/info",
                    params: {'uniqueCode':this.moldSpUsedRecord.uniqueCode},
                    type: "POST",
                    successCallback: function (r) {
                        let moduleSpStock = r.moduleSpStock;
                        if(!moduleSpStock){
                            alert('该型芯不存在或者未入库，请确认！');
                            _this.moldSpUsedRecord.uniqueCode = '';
                            return;
                        }
                        if(moduleSpStock.state == 2){
                            alert('当前型芯已使用，请更换！');
                            _this.moldSpUsedRecord.uniqueCode = '';
                            return;
                        }
                        _this.moldSpUsedRecord.sparePartsName = moduleSpStock.sparePartsName;
                        _this.moldSpUsedRecord.sparePartsSpec = moduleSpStock.sparePartsSpec;
                        _this.moldSpUsedRecord.sparePartsId = moduleSpStock.id;
                    }
                });
            }
        }
    });
    var getMoldSpUsedRecord = function () {
        return vm.moldSpUsedRecord;
    }
</script>
</body>
</html>